import request from '@/utils/http'

// 业务员响应（与后端 StaffResponse 对齐）
export interface StaffResponse {
  id?: number
  name: string
  department: string
  type: string
  pm: string
  status: string | null
  supervisor: string
  is_supervisor: string
  third_department: string
  industry?: string | null
  create_time?: string | null
  update_time?: string | null
}

// 列表响应
export interface StaffListResponse {
  total: number
  items: StaffResponse[]
  page: number
  size: number
  pages: number
}

// 创建/更新请求体
export interface StaffCreate {
  name: string
  department: string
  type: string
  pm: string
  status: string
  supervisor: string
  is_supervisor?: string
  third_department: string
  industry: string
}

export interface StaffUpdate {
  name?: string
  department?: string
  type?: string
  pm?: string
  status?: string
  supervisor?: string
  is_supervisor?: string
  third_department?: string
  industry?: string
}

// 查询参数（与后端 StaffQuery 对齐），注意 current 是 page 的别名
export interface StaffQuery {
  current?: number
  size?: number
  name?: string
  department?: string
  type?: string
  pm?: string
  status?: string
  supervisor?: string
  is_supervisor?: string
  third_department?: string
  industry?: string
  keyword?: string
}

/**
 * 创建业务员
 */
export function createStaff(params: StaffCreate) {
  return request.post<StaffResponse>({
    url: '/system/staffs/create',
    params,
    showSuccessMessage: true
  })
}

/**
 * 获取业务员列表（分页）
 */
export function fetchStaffList(params: StaffQuery) {
  return request.post<StaffListResponse>({
    url: '/system/staffs/list',
    params
  })
}

/**
 * 更新业务员
 */
export function updateStaff(staffId: number, params: StaffUpdate) {
  return request.put<StaffResponse>({
    url: `/system/staffs/${staffId}`,
    params,
    showSuccessMessage: true
  })
}

/**
 * 删除业务员
 */
export function deleteStaff(staffId: number) {
  return request.del<{ message: string }>({
    url: `/system/staffs/${staffId}`,
    showSuccessMessage: true
  })
}